#include "Tierra.h"


Tierra::Tierra(){
	this->m_vertices[0] = glm::vec3(50.0f, 50.0f, 0.0f);
	this->m_vertices[1] = glm::vec3(-50.0f, 50.0f, 0.0f);
	this->m_vertices[2] = glm::vec3(-50.0f, -50.0f, 0.0f);
	this->m_vertices[3] = glm::vec3(50.0f, -50.0f, 0.0f);

	this->m_normales[0] = glm::vec3(0.0f, 0.0f, 1.0f);
	this->m_normales[1] = glm::vec3(0.0f, 0.0f, 1.0f);
	this->m_normales[2] = glm::vec3(0.0f, 0.0f, 1.0f);
	this->m_normales[3] = glm::vec3(0.0f, 0.0f, 1.0f);

	this->m_indexBuffer[0] = 0;
	this->m_indexBuffer[1] = 1;
	this->m_indexBuffer[2] = 2;
	this->m_indexBuffer[3] = 0;
	this->m_indexBuffer[4] = 2;
	this->m_indexBuffer[5] = 3;

	this->m_coordsTex[0] = glm::vec2(0.0f, 0.0f);
	this->m_coordsTex[1] = glm::vec2(10.0f, 0.0f);
	this->m_coordsTex[2] = glm::vec2(10.0f, 10.0f);
	this->m_coordsTex[3] = glm::vec2(0.0f, 10.0f);
}


void Tierra::renderizar(const glm::mat4 &matVista, const glm::mat4 &matProyeccion, const glm::mat4 &matModelo) const {
	// Carga el shader
	const GLuint shaderProgramID = Renderizable::cargarShaderProgram();

	// Empieza a dibujar todo
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	// Los datos de iluminacion, transformacion y texturas
	Renderizable::cargarMatricesTransformacion(matVista, matProyeccion, matModelo);
	Renderizable::cargarDatosIluminacion(matModelo, matVista);
	Renderizable::cargarTextura();

	// Los datos de la figura
	glVertexPointer(3, GL_FLOAT, 0, this->m_vertices);
	glNormalPointer(GL_FLOAT, 0, this->m_normales);
	glTexCoordPointer(2, GL_FLOAT, 0, this->m_coordsTex);
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, this->m_indexBuffer);

	// Listo
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
}

